package iontec.behavior;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;


public class KidEdit extends Activity {
	private EditText mNameText;
	private EditText mBodyText;
	private Long mRowId;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.kid_edit);

		mNameText = (EditText) findViewById(R.id.name);
		mBodyText = (EditText) findViewById(R.id.body);

		Button confirmButton = (Button) findViewById(R.id.submit);

		mRowId = null;
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			String name = extras.getString(GoBDbAdapter.KEY_NAME);
			String body = extras.getString(GoBDbAdapter.KEY_BODY);
			mRowId = extras.getLong(GoBDbAdapter.KEY_ROWID);

			if (name != null) {
				mNameText.setText(name);
			}
			if (body != null) {
				mBodyText.setText(body);
			}
		}

		confirmButton.setOnClickListener(new View.OnClickListener() {

			public void onClick(View view) {
				Bundle bundle = new Bundle();

				bundle.putString(GoBDbAdapter.KEY_NAME, mNameText.getText().toString());
				bundle.putString(GoBDbAdapter.KEY_BODY, mBodyText.getText().toString());
				if (mRowId != null) {
					bundle.putLong(GoBDbAdapter.KEY_ROWID, mRowId);
				}

				Intent mIntent = new Intent();
				mIntent.putExtras(bundle);
				setResult(RESULT_OK, mIntent);
				finish();
			}

		}); 
	       
	   }
	}
